/**
 *Author: chenxiaoyu
 *Date: 2018/4/8
 *Email: 1524904743@qq.com
 *
 */

var persionModule= angular.module('persionModule', []);

persionModule.controller('persionCenterCtrl', [
    '$scope',
    function ($scope) {
    
        $scope.leftMenus= [
            {
                "moduleName":"任务管理",
                "moduleId":"0000000028",
                "childrenList":[
                    {"moduleName":"待处理任务","moduleId":"0000000029","type":"1","parentId":"0000000028","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"已上报任务","moduleId":"0000000031","type":"1","parentId":"0000000028","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsTableTpl.html"},
                    {"moduleName":"已处理任务","moduleId":"0000000039","type":"1","parentId":"0000000028","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"导出任务跟踪","moduleId":"0000000057","type":"1","parentId":"0000000028","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"已上报建议","moduleId":"0000000084","type":"1","parentId":"0000000028","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"}
                    ],
                "type":"1",
                "parentId":"0000000004",
                "moduleLevel":"2"
            },
            // {
            //     "moduleName":"流程管理",
            //     "moduleId":"0000000034",
            //     "childrenList":[
            //         {"moduleName":"组员设置","moduleId":"0000000030","type":"1","parentId":"0000000034","moduleLevel":"3","moduleUrl":"docc/manager/groupMembers/MembersManage.jsp"},
            //         {"moduleName":"在线/离线设置","moduleId":"0000000038","type":"1","parentId":"0000000034","moduleLevel":"3","moduleUrl":"docc/manager/offline/offlineManageByOwn.jsp"}
            //         ],
            //     "type":"1",
            //     "parentId":"0000000004",
            //     "moduleLevel":"2"
            // },
            {
            "moduleName":"知识评价",
            "moduleId":"00000001001",
            "childrenList":[
                {"moduleName":"评价查询","moduleId":"00000001002","type":"1","parentId":"00000001001","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"}
                ],
            "type":"1",
            "parentId":"0000000004",
            "moduleLevel":"2"
            },
            {
                "moduleName":"个人设置",
                "moduleId":"0000000093",
                "childrenList":[
                    {"moduleName":"默认系列设置","moduleId":"0000000094","type":"1","parentId":"0000000093","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"知识收藏","moduleId":"0000000048","type":"1","parentId":"0000000093","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"权限查询","moduleId":"0000000096","type":"1","parentId":"0000000093","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"},
                    {"moduleName":"知识发送查询","moduleId":"00000001027","type":"1","parentId":"0000000093","moduleLevel":"3","moduleUrl":"./client/components/persionCenter/template/tabsPageTpl.html"}
                    ],
                "type":"1",
                "parentId":"0000000004",
                "moduleLevel":"2"
            }
        ];
        $scope.tabDatas= [];
        $scope.openTabls= function (i, u, n) {
            var openObj= {name: n, id: i, url: u, params: {id: i}};
            var stat= true;
            angular.forEach($scope.tabDatas, function (item, k) {
                if (item.id == i){
                    item.url= u + '?_' + new Date().getTime();
                    stat= false;
                    throw '遍历中断';
                }
            })
            if (stat){
                $scope.tabDatas.push(openObj);
            }
        };
        $scope.openProcess = function ( n) {
            var openObj= {name: n, id: 12312, url: './client/components/persionCenter/template/processManagement.html'};
            var stat= true;
            angular.forEach($scope.tabDatas, function (item, k) {
                if (item.id == openObj.id){
                    $scope.showItemId= k;
                    stat= false;
                    throw '遍历中断';
                }
            })
            if (stat){
                $scope.tabDatas.push(openObj);
            }
        };
        
    }
])

persionModule.controller('tabsPageCtrl', [
    '$scope',
    function ($scope) {

        $scope.workType= [{name: '全部', id: 0}, {name: '知识审核', id: 2}, {name: '问题审核', id: 3},
            {name: '知识上报', id: 4}, {name: '附件审核', id: 5}, {name: '知识审核(批量)', id: 6}];
        $scope.isActive= 0;
        $scope.clickWorkType= function (i) {
            $scope.isActive= i;
        }

        // 表头
        $scope.thead= ['系列', '任务编号', '任务类型', '任务主题', '紧急程度', '提交人/行政机构', '提交时间', '操作'];

        $scope.pager= {
            pageNum: 1,
            pageSize: 1,
            totalCount: 5
        }

        $scope.changePage= function (cp, event) {
            $scope.pager.pageNum= cp;
        }
    }
])
persionModule.controller('persionTableCtrl', [
    '$scope',
    '$timeout',
    function ($scope, $timeout) {
        $scope.textList= [{
            text: 'ngDialog 非常不错的弹出窗插件，很轻量，但是功能却很强大，可以看看示例。',
            id: '111'
        },{
            text: 'ng-file-upload 一个上传文件的组件，很不错示例。',
            id: '112'
        },{
            text: 'famous-angular这里顺便可以了解一下famous，也是非常不错的一个关于动画的一个类库，推荐看一下6666666666666666666666666666666666。',
            id: '113'
        }]

        $scope.test= '这是测试字段';
    }
])
persionModule.controller('processManagePageCtrl', [
    '$scope',
    function ($scope) {
        $scope.items= [
            {name: '配置项1', detail: '详情1',des: '描述1',source:'附件1',people:'人员1'},
            {name: '配置项2', detail: '详情2',des: '描述2',source:'附件2',people:'人员2'},
            {name: '配置项3', detail: '详情3',des: '描述3',source:'附件3',people:'人员3'},
            {name: '配置项4', detail: '详情4',des: '描述4',source:'附件4',people:'人员4'},
            {name: '配置项5', detail: '详情5',des: '描述5',source:'附件5',people:'人员5'},
            {name: '配置项6', detail: '详情6',des: '描述6',source:'附件6',people:'人员6'}
        ];
        $scope.currentItem = {};
        $scope.passInfo = function (item) {
            $scope.currentItem = item;
        }; 
        $scope.setInfo = function (info) {
            $scope.currentDetail= info;
        };     
        $scope.roleList  = [
            
            { "roleName" : "经理", "roleId" : "role2", "children" : [
                { 
                    "roleName" : "系列经理", 
                    "roleId" : "role11", 
                    "collapsed" : true, 
                    "children" : [
                        { "roleName" : "张经理", "roleId" : "role1212", "children" : [] }
                    ] 
                },
                { 
                    "roleName" : "部门经理", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "王经理", "roleId" : "role1211", "children" : [] },
                    { "roleName" : "柏经理", "roleId" : "role1212", "children" : [] }
                    ]
                },
                { 
                    "roleName" : "项目经理", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "林经理", "roleId" : "role1211", "children" : [] }
                    ]
                },
                { 
                    "roleName" : "小组经理", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "李经理", "roleId" : "role1211", "children" : [] },
                    { "roleName" : "刘经理", "roleId" : "role1212", "children" : [] }
                    ]
                }
            ]},
            { "roleName" : "员工", "roleId" : "role2", "children" : [
                { 
                    "roleName" : "技术部", 
                    "roleId" : "role11", 
                    "collapsed" : true, 
                    "children" : [
                        { "roleName" : "张先生", "roleId" : "role1212", "children" : [] }
                    ] 
                },
                { 
                    "roleName" : "财务部", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "王先生", "roleId" : "role1211", "children" : [] },
                    { "roleName" : "柏小姐", "roleId" : "role1212", "children" : [] }
                    ]
                },
                { 
                    "roleName" : "工程部", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "林先生", "roleId" : "role1211", "children" : [] }
                    ]
                },
                { 
                    "roleName" : "后勤部", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "李先生", "roleId" : "role1211", "children" : [] },
                    { "roleName" : "刘女士", "roleId" : "role1212", "children" : [] }
                    ]
                }
            ]},
            { "roleName" : "管理员", "roleId" : "role2", "children" : [
                { 
                    "roleName" : "前端开发", 
                    "roleId" : "role11", 
                    "collapsed" : true, 
                    "children" : [
                        { "roleName" : "张前端", "roleId" : "role1212", "children" : [] }
                    ] 
                },
                { 
                    "roleName" : "后台管理", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "王后台", "roleId" : "role1211", "children" : [] }
                    ]
                },
                { 
                    "roleName" : "运维管理", 
                    "roleId" : "role12", 
                    "children" : [
                    { "roleName" : "林运维", "roleId" : "role1211", "children" : [] }
                    ]
                }
            ]}
        ];
        $scope.processItems = [
            {
                "stepName" : "步骤一",
                "roleName" : "直接领导",
                "roleDesc" : "分组负责人",
                "isChecked": "",
                "nodeId":"process001"
            },
            {
                "stepName" : "步骤二",
                "roleName" : "部门长",
                "roleDesc" : "本部门领导",
                "isChecked": "",
                "nodeId":"process002"
            },
            {
                "stepName" : "步骤三",
                "roleName" : "系列长",
                "roleDesc" : "系列领导",
                "isChecked": "",
                "nodeId":"process003"
            },
            {
                "stepName" : "步骤四",
                "roleName" : "总经理助理",
                "roleDesc" : "如果需要的话",
                "isChecked": "",
                "nodeId":"process004"
            },
            {
                "stepName" : "步骤五",
                "roleName" : "首席执行官",
                "roleDesc" : "如果需要的话",
                "isChecked": "",
                "nodeId":"process005"
            },
            {
                "stepName" : "步骤六",
                "roleName" : "完成",
                "roleDesc" : "通知发起人",
                "isChecked": "",
                "nodeId":"process006"
            }
        ];
        $scope.addProcess = function(){
            var item = {
                "stepName" : "新步骤",
                "roleName" : "新节点",
                "roleDesc" : "描述信息",
                "isChecked": "",
                "nodeId": Date.now().toString()
            };
            $scope.processItems.push(item);
        }
        $scope.removeBtn = false
        $scope.removeProcess = function(){
            
        }

      $scope.toggle = function (scope) {
        scope.toggle();
      };

      $scope.newSubItem = function (scope) {
        var nodeData = scope.$modelValue;
        nodeData.nodes.push({
          id: nodeData.id * 10 + nodeData.nodes.length,
          title: nodeData.title + '.' + (nodeData.nodes.length + 1),
          nodes: []
        });
      };

      $scope.tree1 = [{
        'id': 1,
        'title': 'tree1 - item1',
        'nodes': [
            {
                'id': 1.1,
                'title': 'tree1 - item1.1',
                'nodes': []
            }
        ]
      }, {
        'id': 2,
        'title': 'tree1 - item2',
        'nodes': []
      }, {
        'id': 3,
        'title': 'tree1 - item3',
        'nodes': [
            {
                'id': 3.1,
                'title': 'tree1 - item3.1',
                'nodes': []
            },
            {
                'id': 3.2,
                'title': 'tree1 - item3.2',
                'nodes': [
                    {
                        'id': '3.2.1' ,
                        'title': 'tree1 - item3.2.1',
                        'nodes': []
                    }
                ]
            }
        ]
      }, {
        'id': 4,
        'title': 'tree1 - item4',
        'nodes': []
      }];
      $scope.tree2 = [{
        'id': 1,
        'title': 'tree2 - item1',
        'nodes': []
      }, {
        'id': 2,
        'title': 'tree2 - item2',
        'nodes': []
      }, {
        'id': 3,
        'title': 'tree2 - item3',
        'nodes': []
      }, {
        'id': 4,
        'title': 'tree2 - item4',
        'nodes': []
      }];
    }
])